<template>
  <el-dialog
    title="试卷判分列表"
    :visible.sync="visible">
    <el-table
    :data="dataList"
    border
    >
      <el-table-column align="center" type="index" header-align="center" width="80px" label="序号"/>
      <el-table-column prop="realname" label="姓名" align="center"></el-table-column>
      <el-table-column prop="deptName" label="部门名称" align="center"></el-table-column>
      <el-table-column prop="isPass" label="是否及格" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isPass === 0">未及格</el-tag>
          <el-tag v-else>及格</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="score" label="分数" align="center"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="200" label="操作">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="判分" placement="top">
            <el-button type="text" icon="el-icon-document-checked" @click="judgment(scope.row.examId, scope.row.userId)"></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      ref="fixedPag"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="dataForm.page"
      :page-sizes="[10, 20, 50]"
      :page-size="dataForm.limit"
      :total="dataForm.totalCount"
      layout="total, sizes, prev, pager, next, jumper"
    />
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="visible = false">确 定</el-button>
    </div>

    <test-paper ref="testPaper" @refreshDataList="getList"></test-paper>
  </el-dialog>
</template>

<script>
  import TestPaper from './testPaper'
  export default {
    data() {
      return {
        visible: false,
        loading: false,
        dataList: [],
        dataForm: {
          examId : '',
          page: 1,
          totalCount: 0,
          limit: 10
        }
      }
    },
    components: {
      TestPaper
    },
    methods: {
      init(examId ) {
        this.visible = true
        this.dataForm.examId  = examId
        this.getList()
      },
      getList() {
        this.$http({
          url: this.$http.adornUrl('/exam-admin/score/scoreList'),
          method: 'post',
          data: {
            examId: this.dataForm.examId,
            page: this.dataForm.page,
            limit: this.dataForm.limit
          }
        }).then(res => {
          if (res && res.code === 200) {
            this.dataList = res.data.list
            this.dataForm.totalCount = res.data.totalCount
          }
        })
      },
      judgment(examId, userId) {
        this.$nextTick(_ => {
          this.$refs.testPaper.init(examId, userId)
        })
      },
      sizeChangeHandle(val) {
        this.dataForm.page = val
        this.dataForm.page = 1
        this.getList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.dataForm.limit = val
        this.getList()
      },
      arms() {
        return {
          markId: this.dataForm.markId,
          pCode: this.dataForm.pCode,
          enable: this.dataForm.enable,
          grade: this.dataForm.grade,
          isRepeat: this.dataForm.isRepeat,
          quesSpacing: this.dataForm.quesSpacing,
          topGrade: this.dataForm.topGrade,
          gradeType: this.dataForm.gradeType,
          awardGrade: this.dataForm.awardGrade
        }
      },
      async onsubmit() {
        let res = await this.$http({
          url: this.$http.adornUrl(`/integral-admin/integral/examrule/addOrUpdateExamRule`),
          method: 'post',
          data: this.arms()
        })
        console.log(this.arms)
        if (res.code === 200) {
          this.$notify.success({title: '成功', message: '保存成功！'})
          this.visible = false
        }
      }
    }
  }
</script>

<style scoped>

</style>
